<?php

$is_command = php_sapi_name() != 'cli' ? false : true;

if (!$is_command) {
    exit('不是命令行');
}

date_default_timezone_set('PRC');

ini_set('display_errors', 0);
ini_set('log_errors', 1);
set_time_limit(0);
ini_set('memory_limit','512M');
error_reporting(E_ALL & ~E_NOTICE);

//自动加载
require("config.php");
require(WEBROOT.'/Lib/'.'autoload.php');

require(WEBROOT.'/data/'.'xmlPackage.php');
//require(WEBROOT.'/data/'.'excelPackage.php');
//require(WEBROOT.'/data/'.'csvPackage.php');
//require(WEBROOT.'/controller/'.'csvExport.class.php');
//require(WEBROOT.'/Controller/'.'xmlExport.class.php');

// d 记录d
$parms = getopt("d:");

if (empty($parms['d'])) {
    exit('参数错误');
}

$id = $parms['d'];

//use Controller\ExcelExport;
//$Export = new ExcelExport($id, $dataPackage);

//use Controller\CsvExport;
//$Export = new CsvExport($id,$dataPackage);

use Controller\XmlExport;
$Export = new XmlExport($id, $dataPackage);

//导出
$timeStart = microtime(true);

$res = $Export->run(10000);

if (!$res) {
    echo $Export->getError().PHP_EOL;
}

function garbage($signal){
    echo "signel $signal received\n" ;

    while (($pid = pcntl_waitpid(-1, $status, WNOHANG))> 0){
        echo "\t child end pid $pid , status $status\n" ;
    }
}

echo floor((memory_get_peak_usage())/1024/1024)."MB";
echo "\n";
echo microtime(true) - $timeStart;
echo "\n";
exit;
?>
